﻿using Fish.DAL;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
/* This Model contains all of the Event's information starting from it's description and going throught it's Image and location
 * and start date and end date if found and the number of guests if required!
 * Each Event information model must be linked with an event for logical reasons
 * Each class contains create and modified times for security reasons
 */
namespace Fish.Models
{
    public class EventInfo
    {
        public int ID { get; set; }

        public int EventsID { get; set; }

        public byte[] EventImage { get; set; }

        [Required]
        public string Description { get; set; }


        public string Address { get; set; }

        [Required]
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        public DateTime StartDate { get; set; }

        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        public DateTime EndDate { get; set; }

        [Display(Name="Number of Maximum Guests")]
        public int MaximumGuests { get; set; }

        [DataType(DataType.DateTime)]
        [ScaffoldColumn(false)]
        public DateTime Created { get; set; }

        [DataType(DataType.DateTime)]
        [ScaffoldColumn(false)]
        public DateTime Modified { get; set; }

        public virtual Events Event { get; set; }

        public EventInfo()
        {
            this.Created = DateTime.Now;
            this.Modified = DateTime.Now;
        }

        public Boolean isMember(int userID)
        {
            FishContext db = new FishContext();
            List<EventUserRelations> eur = db.EventUserRelations.Where(e => e.EventsID == EventsID).ToList();
            foreach (EventUserRelations er in eur)
            {
                if (er.UsersID == userID)
                {
                    return true;
                }
            }
            return false;
        }
    }
}